//#include "widget.h"
#include "ui_widget.h"

#include "ConversionScreen.h"

#include <QApplication>
#include <QHBoxLayout>
#include <QLabel>
#include <QSpinBox>

extern "C" {int sumBirth(const int year,const int mon,const int day);}; //将c函数包含进来

/***************************************
Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}
****************************************/
ConversionScreen::ConversionScreen():QWidget()  //构造函数的实现
{
    createScreen();//调用自定义函数
}

void ConversionScreen::createScreen()
{
    //window=new QWidget;
    this->setWindowTitle("Enter Your BirthDay");
    spinYear=new QSpinBox;
    spinMon=new QSpinBox;
    spinDay=new QSpinBox;
    spinYear->setRange(1900,2100);
    spinMon->setRange(1,12);
    spinDay->setRange(1,31);
    spinYear->setValue(1988);

    labelYear=new QLabel("year");
    labelMon=new QLabel("mon");
    labelDay=new QLabel("day");
    labelDays=new QLabel("days");
    textDay=new QSpinBox;
    textDay->setRange(0,100000);
    layout=new QHBoxLayout;

    QObject::connect(spinYear,SIGNAL(valueChanged(int)),this,SLOT(setDays()));
    QObject::connect(spinMon,SIGNAL(valueChanged(int)),this,SLOT(setDays()));
    QObject::connect(spinDay,SIGNAL(valueChanged(int)),this,SLOT(setDays()));

    layout->addWidget(spinYear);
    layout->addWidget(labelYear);
    layout->addWidget(spinMon);
    layout->addWidget(labelMon);
    layout->addWidget(spinDay);
    layout->addWidget(labelDay);
    layout->addWidget(textDay);
    layout->addWidget(labelDays);
    this->setLayout(layout);
    this->show();
}
void ConversionScreen::createDays()
{
    yearNum=spinYear->value();
    monNum=spinMon->value();
    dayNum=spinDay->value();
    daysNum=sumBirth(yearNum,monNum,dayNum);//C 函数的调用，其实很简单
}
void ConversionScreen::setDays()    //slot函数实现,(想想slot的规则）
{
    createDays();
    textDay->setValue(daysNum);
}
